/**
 * Created by Administrator on 2017/3/13 0013.
 */
Hajime={
    Create:function(){
        var hajime={};
        var loader=new PIXI.loaders.Loader();
        var graphic_bg,graphic_loadingBottom,graphic_loading;
        var text_progress;
        var sp_logo;

        var bl_musicLoad=false;
        var bl_picLoad=false;

        var whole=new PIXI.DisplayObjectContainer();
        var arr_assets=[];
        arr_assets.push(
            'pixi/images/op.png',
            'pixi/images/bg.png',
            'pixi/images/btnBG.png',
            'pixi/images/btnClick.png',
            'pixi/images/btnGray.png',
            'pixi/images/btnHover.png'
            );

        function loadProgressHandler(loader,resource){
                text_progress.text=Math.floor(loader.progress)+"%";
                graphic_loading.scale.x=loader.progress/100;
        }
        function completeHandler(){
            bl_picLoad=true;
        }
        document.addEventListener("audioLoaded",function(){
            bl_musicLoad=true;
        })


        var timer=setInterval(function(){
            if(bl_picLoad==true&&bl_musicLoad==true){
                AllLoaded();
                clearTimeout(timer);
            }
        },100);

        function AllLoaded(){
            TweenMax.to(graphic_bg, 1, {alpha: 0, ease: Cubic.easeInOut});
            TweenMax.to(sp_logo, 0.7, {alpha: 0, y: sp_logo.y - 100, ease: Cubic.easeInOut});
            TweenMax.to(graphic_loading, 0.7, {alpha: 0, y: graphic_loading.y + 100, ease: Cubic.easeInOut});
            TweenMax.to(graphic_loadingBottom, 0.7, {alpha: 0, y: graphic_loadingBottom.y + 100, ease: Cubic.easeInOut});
            TweenMax.to(text_progress, 0.7, {alpha: 0, y: text_progress.y + 100, ease: Cubic.easeInOut});

            console.log("HajimeCompleted");
            document.dispatchEvent(new CustomEvent("HajimeCompleted",{detail:loader.resources}));
        }




        hajime.ReturnWhole=function(){
            return whole;
        }

        hajime.initial=function(){
            graphic_bg = new PIXI.Graphics();
            graphic_bg.beginFill(0x0);
            graphic_bg.drawRect(0,0,pixiStageW,pixiStageH);
            whole.addChild(graphic_bg);

            graphic_loadingBottom=new PIXI.Graphics();
            graphic_loadingBottom.beginFill(0xcccccc);
            graphic_loadingBottom.drawRect(0,0,300,2);
            graphic_loadingBottom.x=(pixiStageW-graphic_loadingBottom.width)/2;
            graphic_loadingBottom.y=(pixiStageH/2)+40;
            whole.addChild(graphic_loadingBottom);

            graphic_loading=new PIXI.Graphics();
            graphic_loading.beginFill(0xff6600);
            graphic_loading.drawRect(0,0,300,2);
            graphic_loading.x=(pixiStageW-graphic_loading.width)/2;
            graphic_loading.y=(pixiStageH/2)+40;
            graphic_loading.scale.x=0;
            whole.addChild(graphic_loading);

            sp_logo=new PIXI.Sprite.fromImage('pixi/images/LOGO.png');
            sp_logo.anchor.set(0.5);
            sp_logo.x=pixiStageW/2;
            sp_logo.y=pixiStageH/2-50;
            // whole.addChild(sp_logo);

            text_progress= new PIXI.Text('0%',{fontFamily : 'Arial', fontSize: 20, fill : 0xcccccc, align : 'center'});
            text_progress.anchor.x=0.5;
            text_progress.anchor.y=0.5;
            text_progress.x = pixiStageW/2;
            text_progress.y = pixiStageH/2+80;
            whole.addChild(text_progress);


            loader
                .add(arr_assets)
                .on("progress",loadProgressHandler)
                .load(completeHandler);
        };


        hajime.initial();





        return hajime;
    }
}